def hello():
    a1 = "hello1"
    a2 = "hello2"
    a3 = "hello3"
    a4 = "hello4"
    print(a1)
    print(a2)
    print(a3)
    print(a4)


def printTest():
    print("'test'")
    print('"test"')
    print("\"test\"")
    print('\'test\'')


# Fibonacci series:
# the sum of two elements defines the next
def fibonacciSequence(n):
    a, b = 0, 1
    while a < n:
        print(a, end=", ")
        a, b = b, a + b
    print("\n")


# if控制语句
def ifTest():
    x = int(input("Please enter an integer: "))
    if x < 0:
        x = 0
        print('Negative changed to zero')
    elif x == 0:
        print('Zero')
    elif x == 1:
        print('Single')
    else:
        print('More')


# for 语句
# Measure some strings:
def forTest():
    words = ['cat', 'window', 'defenestrate']
    for w in words:
        print(w, len(w))


# 如果在循环内需要修改序列中的值（比如重复某些选中的元素），推荐你先拷贝一份副本。
def forTest2():
    words = ['cat', 'window', 'defenestrate']
    for w in words[:]:  # Loop over a slice copy of the entire list.
        if len(w) > 6:
            words.insert(0, w)
    print(words)


# range() 函数¶
def forTest3():
    for i in range(5):
        print(i, end=",")
    print("\n")
    for i in range(5, 10):
        print(i, end=',')
    a = ['Mary', 'had', 'a', 'little', 'lamb']
    print("\n")
    for i in range(len(a)):
        print(i, a[i])
    print("\n")


# break 和 continue 语句，以及循环中的 else 子句¶
def sepTest():
    for n in range(2, 100):
        for x in range(2, n):
            if n % x == 0:
                print(n, 'equals', x, '*', n // x)
                break
        else:
            # loop fell through without finding a factor
            print(n, 'is a prime number')


def ask_ok(prompt, retries=4, reminder='Please try again!'):
    while True:
        ok = input(prompt)
        if ok in ('y', 'ye', 'yes'):
            return True
        if ok in ('n', 'no', 'nop', 'nope'):
            return False
        retries = retries - 1
        if retries < 0:
            raise ValueError('invalid user response')
        print(reminder)


# 解包参数，包括*name，**name
def cheeseshop(kind, *arguments, **keywords):
    print("-- Do you have any", kind, "?")
    print("-- I'm sorry, we're all out of", kind)
    for arg in arguments:
        print(arg)
    print("-" * 40)
    for kw in keywords:
        print(kw, ":", keywords[kw])


def parrot(voltage, state='a stiff', action='voom'):
    print("-- This parrot wouldn't", action, end=' ')
    print("if you put", voltage, "volts through it.", end=' ')
    print("E's", state, "!")


# hello()
# printTest()
# fibonacciSequence(1000)
# ifTest()
# forTest()
# forTest2()
# forTest3()

# sepTest()
# print(ask_ok("p"))
# cheeseshop("Limburger", "It's very runny, sir.",
#            "It's really very, VERY runny, sir.",
#            shopkeeper="Michael Palin",
#            client="John Cleese",
#            sketch="Cheese Shop Sketch")
arg = ["It's very runny, sir.", "It's really very, VERY runny, sir."]
dic = {"shopkeeper": "Michael Palin",
       "client": "John Cleese",
       "sketch": "Cheese Shop Sketch"}

# cheeseshop("Limburger", *arg, **dic)
d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
parrot(**d)
